/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package library;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class UserRecord extends Record{
    public UserRecord(int id, String name, String pass) {
        data = new String[]{"" + id, name, pass};
    }

    public UserRecord(int id, String name) {
        data = new String[]{"" + id, name};
    }

    public UserRecord() {
    }

    @Override
    public Record[] init() {
        int size = 0;
        try {
            ResultSet rs = DB.execQuery("SELECT count(*) as total FROM Admins");
            rs.next();
            size = rs.getInt("total");
            rs.close();
        }
        catch (SQLException ex) {
            Logger.getLogger(UserRecord.class.getName()).log(Level.SEVERE, null, ex);
        }
        UserRecord[] q = new UserRecord[size];
        int i = 0;
        if (size > 0) {
            try {
                ResultSet rs = DB.execQuery("SELECT * FROM Admins");
                while (rs.next()) {
                    q[i] = new UserRecord(rs.getInt("ID"), rs.getString("UserName"), rs.getString("Password"));
                    i++;
                }
                rs.close();
            }
            catch (SQLException ex) {
                Logger.getLogger(UserRecord.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return q;
    }
}
